package 多线程.Threadpool;

import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import java.util.function.Function;

public class ThenApplyDemo {

    public static void main(String[] args) throws ExecutionException, InterruptedException {
        //返回一个"hello"
        CompletableFuture<String> future = CompletableFuture.supplyAsync(() -> "hello");
        CompletableFuture<String> future1 = future.thenApply(new Function<String, String>() {
            @Override
            public String apply(String s) {
                return s+" world";
            }
        });
        String s = future1.get();
        System.out.println(s);//hello world
    }
}